package com.greatwqs.wmall.message.producer.service;

import org.springframework.kafka.core.KafkaTemplate;
import org.springframework.stereotype.Service;

import com.greatwqs.wmall.message.producer.config.KafkaTopicConfig;

@Service
public class KafkaProducerService {

    private final KafkaTemplate<String, String> kafkaTemplate;

    public KafkaProducerService(KafkaTemplate<String, String> kafkaTemplate) {
        this.kafkaTemplate = kafkaTemplate;
    }

    public void sendMessage(String message) {
        kafkaTemplate.send(KafkaTopicConfig.TOPIC_NAME, message);
        System.out.println("Sent message: " + message);
    }

    public void sendMessageToPartitionedTopic(String message) {
        kafkaTemplate.send(KafkaTopicConfig.TOPIC_PARTITIONED_NAME, message);
        System.out.println("Sent message to partitioned topic: " + message);
    }
}